Retrievers
A Retriever is responsible for finding the most relevant information from a knowledge source before the language model generates a response. Rather than searching every document, the retriever selects only the pieces of information that are most useful for answering the user’s question. Retrievers are the bridge between your knowledge base and the language model.What is a Retriever?
A retriever accepts a query and returns relevant documents or document chunks. Conceptually:Why Retrievers?
Knowledge bases can contain thousands or even millions of documents. Sending all of that information to a language model is impossible because of context window limits. Instead:Retrieval Workflow
The complete retrieval process looks like this.Retriever Responsibilities
A retriever typically performs several tasks:- receive a query
- generate a query embedding
- search the knowledge index
- rank results
- return the best matches
Example
Knowledge base:Top-K Retrieval
Most retrievers return the K most relevant results.Metadata Filtering
Retrievers can limit searches using document metadata. Example:Hybrid Retrieval
Some systems combine multiple search techniques.Custom Retrievers
Applications can implement their own retrieval strategies. Examples include:- SQL database search
- API-based retrieval
- Elasticsearch
- cloud search services
- graph databases
- enterprise search engines
Using a Retriever
Conceptually, attach a retriever to an agent.Retriever vs Knowledge
Knowledge stores information. Retrievers search that information.
Both are required for effective RAG systems.
Performance
Retriever performance depends on:- embedding quality
- vector database performance
- document chunk size
- search algorithm
- metadata filtering
- ranking strategy
Best Practices
- Retrieve only the most relevant documents.
- Keep K relatively small.
- Use metadata filtering whenever possible.
- Combine semantic search with keyword search for better accuracy.
- Rank results before sending them to the language model.
- Monitor retrieval quality as your knowledge base grows.
